package com.dayuan.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dayuan.bean.BackUser;
import com.dayuan.service.AdminUserService;
import com.dayuan.utils.pageHelper;

@Controller
@RequestMapping("/review")
public class ReviewController {

	@Resource
	private AdminUserService adminUserService;


	// 商家审核（分页查看）
	@RequestMapping(value = "/page.shtml", method = { RequestMethod.POST, RequestMethod.GET })
	public String paging(Integer pageIndex, ModelMap modelMap) {
		try {

			if (pageIndex == null) {
				pageIndex = 1;
			}
			// 查询总行数
			int totalCount = adminUserService.selectAdminUserTotal();

			pageHelper pageHelper = new pageHelper(pageIndex, totalCount);
			pageHelper.setPageNum(2);
			List<BackUser> adminUser = adminUserService.selectAdminUserLimit(pageHelper.getStartIndex(),
					pageHelper.getPageNum());

			// 传给前端总页数和当前页goods
			modelMap.addAttribute("AdminUser", adminUser);
			modelMap.addAttribute("pageHelper", pageHelper);

			return "review";
		} catch (Exception e) {
			e.printStackTrace();
			modelMap.addAttribute("msg", "网络异常");
			return "review";
		}

	}

	// 审核通过
	@RequestMapping(value = "/updatepass.shtml", method = { RequestMethod.POST, RequestMethod.GET })
	public String pass(int id) {
		try {
			adminUserService.updateUserPass(id);
			return "redirect:page.shtml";
		} catch (Exception e) {
			e.printStackTrace();
			return "redirect:page.shtml";
		}

	}

	// 审核不通过
	@RequestMapping(value = "/updatenotpass.shtml", method = { RequestMethod.POST, RequestMethod.GET })
	public String notPass(int id) {
		try {
			adminUserService.updateUserNotPass(id);
			return "redirect:page.shtml";
		} catch (Exception e) {
			e.printStackTrace();
			return "redirect:page.shtml";
		}

	}

}